Skip to content

Conversation

@vasily-kirichenko
Copy link
Contributor

open Microsoft.FSharp.Compiler.SourceCodeServices
open System.IO
open System.Diagnostics
open System

let sysLib nm = 
    if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows 
        @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\" + nm + ".dll"
    else
        let sysDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()
        let (++) a b = System.IO.Path.Combine(a,b)
        sysDir ++ nm + ".dll"

let fsCore4300() = 
    if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows 
        @"C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.0.0\FSharp.Core.dll"  
    else 
        sysLib "FSharp.Core"

let mkProjectCommandLineArgs (dllName, fileNames) = 
    [|  yield "--simpleresolution" 
        yield "--noframework" 
        yield "--debug:full" 
        yield "--define:DEBUG" 
        yield "--optimize-" 
        yield "--out:" + dllName
        yield "--doc:test.xml" 
        yield "--warn:3" 
        yield "--fullpaths" 
        yield "--flaterrors" 
        yield "--target:library" 
        for x in fileNames do 
            yield x
        let references = 
            [ yield sysLib "mscorlib"
              yield sysLib "System"
              yield sysLib "System.Core"
              yield fsCore4300() ]
        for r in references do
                yield "-r:" + r |]

let checker = FSharpChecker.Create(keepAllBackgroundResolutions = false, keepAssemblyContents = false)

module Project1 = 
    open System.IO

    let fileNamesI = [ for i in 1 .. 10 -> (i, Path.ChangeExtension(Path.GetTempFileName(), ".fs")) ]
    let base2 = Path.GetTempFileName()
    let dllName = Path.ChangeExtension(base2, ".dll")
    let projFileName = Path.ChangeExtension(base2, ".fsproj")
    let fileSources = [ for (i,f) in fileNamesI -> (f, "module M" + string i) ]
    for (f,text) in fileSources do File.WriteAllText(f, text)
    let fileSources2 = [ for (i,f) in fileSources -> f ]

    let fileNames = [ for (_,f) in fileNamesI -> f ]
    let args = mkProjectCommandLineArgs (dllName, fileNames)
    let options =  checker.GetProjectOptionsFromCommandLineArgs (projFileName, args)

[<EntryPoint>]
let main _ = 
    printfn "Press a key to start checking"
    Console.ReadKey() |> ignore
    let opts = checker.GetProjectOptionsFromProjectFile (@"d:\git\FSharp.Data\src\FSharp.Data.fsproj")
    let res = checker.ParseAndCheckProject opts |> Async.RunSynchronously
    checker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients()
    printfn "Done in %O" sw.Elapsed
    Console.ReadKey() |> ignore
    0

Before

before

After

after

…ker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients
dsyme added a commit that referenced this pull request Sep 14, 2015
…portsCache

clean up IncrementalFSharpBuild.frameworkTcImportsCache
@dsyme dsyme merged commit 222a5df into fsharp:master Sep 14, 2015
@dsyme
Copy link
Contributor

dsyme commented Sep 14, 2015

Great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants